/*
 * @lc app=leetcode.cn id=896 lang=java
 *
 * [896] 单调数列
 */

// @lc code=start
class Solution
{
  public boolean isMonotonic(int[] nums)
  {
    int n = nums.length;
    return isMonotonic(nums, 1, 1, n) || isMonotonic(nums, -1, n - 2, -1);
  }

  public boolean isMonotonic(int[] nums, int step, int begin, int end)
  {
    for (; begin != end; begin += step) {
      if (nums[begin] < nums[begin - step])
        return false;
    }
    return true;
  }
}
// @lc code=end
